// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import iview from 'iview'
import axios from '../static/http'

import 'iview/dist/styles/iview.css'
import cookie from '../static/cookie.js'
import time from'../static/formatDate.js'
import {JSEncrypt} from '../static/jsencrypt.min'
import ossClient from '../static/aliyun-oss-sdk-4.4.4.min'
import utils from '../static/utils';
import cityData from '../static/city';
import ElementUI from 'element-ui';

Vue.use(ElementUI);

var qs = require('qs');


Vue.use(iview)
Vue.use(cookie);
Vue.use(time);

Vue.prototype.cookie = cookie;
Vue.prototype.$http = axios;
Vue.prototype.$JSEncrypt = new JSEncrypt();
Vue.prototype.formatDate = time.formatDate;
Vue.prototype.goToLogin = time.goToLogin;
Vue.prototype.toMoneySercurity=time.toMoneySercurity;
Vue.prototype.utils = utils;
Vue.prototype.cityData = cityData;


// Vue.prototype.host='http://test.kaipai.net/';
//Vue.prototype.host="http://192.168.6.3:8082";
Vue.prototype.host=window.location.host;
/*
Vue.prototype.aliyun='http://kp-test.img-cn-shenzhen.aliyuncs.com/';
*/
//Vue.prototype.host='http://192.168.1.4:8081/';
Vue.prototype.service = "/nb-bs/api";
Vue.prototype.emtService = "/emt-serv";
Vue.prototype.$Message.config({
  top: 200,
  duration: 1.5
});


/*上传货币logo*/
Vue.prototype.uploadFile = function (fileId,pic,tishi) {
  var _self = this;
  var url = '';
  var times = new Date();

  var random = parseInt(Math.random()*(1000-1+1)+1000);
  var caution = document.getElementById(tishi);
  caution.textContent='上传中';
  caution.style.color='#3b7bea'
  return ossClient.urllib.request(_self.host+_self.service+'/upload/getOssStsToKen', {
    method: 'post'
  }).then(function (result) {
    var creds = JSON.parse(result.data);
    var aliyun = creds.result.data.domain;//2
    var client = new ossClient.Wrapper({
      region: 'oss-cn-shenzhen',
      accessKeyId: creds.result.data.accessKeyId,
      accessKeySecret: creds.result.data.accessKeySecret,
      stsToken: creds.result.data.securityToken,
      bucket: creds.result.data.bucket
    });
    var file = document.getElementById(fileId).files[0];
    var key = _self.formatDate(new Date(),'yyyyMMdd')+'/'+_self.formatDate(new Date(),'yyyyMMddhhmmss')+random;
    return client.multipartUpload(key, file, {

    }).then(function (res) {
      caution.textContent='上传成功';
      caution.style.color='#3b7bea'
      document.getElementById(pic).src=aliyun+res.name;
    }).catch(function (err) {
      caution.textContent='上传失败';
      caution.style.color='red'
    });
  }).catch(function (err) {
    caution.textContent='上传失败';
    caution.style.color='red'
  });
}


/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  template: '<App/>',
  components: { App },
  data:()=>({
    pubkey:''
  })
})
